<?php
$auth = Auth::getAuth('current_user');

$db = new Database;
$fs = new functions;
$search = new Search();
$myrequest = new My_Request();
$userID = $auth['id'];
$returnJson = array();
	    $search_value = $_POST['search_value'];
	    $forms_array = $search->getCompaniesForm("AND is_active = 1");
	    $start = $_POST['start'];
	    // $start = 0;
	    $countRecord = 0;
	    $unionQuery = "";
	    $ctr = 0;
	    $limit = "";
	    foreach ($forms_array as $forms) {
	       $id =  $forms['id'];
	       $form_tablename = $forms['form_table_name'];
	       $unionQuery.=$myrequest->setQuery($form_tablename,$id,$search_value);
	       if($ctr<count($forms_array)-1){
		 $unionQuery.=" UNION ALL ";
	       }
	       $ctr++;
	     }
	     if($start!=""){
	       $limit = " LIMIT $start, 10";
	     }
	     
	     $unionQuery =  $unionQuery.$limit; 
	     // echo $unionQuery;
	     $return = $db->query($unionQuery,"array");
	     foreach ($return as $request) {
		 $request['user_image'] = post::avatarPic("tbuser",$request['requestor_id'],"30","30","small","avatar");
		 array_push($returnJson, $request);
	     }
	   echo json_encode($returnJson);

?>